﻿
////////////////////////////////////////////////////////////////////////////////////////////
// 文件名: SysRoleDAL.gen.cs
//
// 模块名称: SysRoleDal
//
// 作者: LPC
//
// 历史记录（记录修改记录，修改文件后请添加修改记录，注明修改时间、修改人，修改内容）:
// 13-2-20    LPC    创建文件
////////////////////////////////////////////////////////////////////////////////////////////

using System;
using System.Data;
using System.Collections.Generic;
using System.Data.Common;
using System.Text;
using System.Data.SqlClient;
using Common;
using Model;

namespace DAL
{
    /// <summary>
    /// SysRoleInfo表数据访问层
    /// </summary>
    public partial class SysRoleDAL
    {
        /// <summary>
        /// 根据Id字段获取SysRoleInfo实体对象
        /// </summary>
        /// <param name="id">Id</param>
        /// <returns>SysRoleInfo实体对象</returns>
        public static SysRoleInfo GetInfoById(string id)
        {
            IList<SysRoleInfo> list = new List<SysRoleInfo>();

            //创建DbCommand对象
            HIDB.dbo cmd = HIDB.common.make();

            //添加输入输出参数
            IDataParameter[] sqlparams = { 
             new SqlParameter("@Id",id)    
            };

            //执行命令返回结果
            try
            {
                DataTable dt = cmd.StoredDataTable("UP_SysRoleInfo_Select", sqlparams);
                list = Common.DBConvert.DataTableToList<SysRoleInfo>(dt); ;
            }
            catch (Exception ex)
            {
                Logger.LogError("UP_Sys_SysRoleInfo_Insert", "UP_Sys_SysRoleInfo_Insert", 0, 1, ex, "", "");
            }
            if (list != null && list.Count > 0)
            {
                return list[0];
            }
            else
            {
                return null;
            }
        }
         
        /// <summary>
        /// 往SysRoleInfo表内添加新记录
        /// </summary>
        /// <param name="sysRoleInfo">SysRoleInfo实体对象</param>
        /// <returns>添加记录索引值</returns>
        public static int Insert(SysRoleInfo sysRoleInfo)
        {
            int num = -1;

            //创建cmd对象
            HIDB.dbo cmd = HIDB.common.make();

            //添加输入输出参数
            IDataParameter[] sqlparams = {
            new SqlParameter("@Id",sysRoleInfo.Id),
            new SqlParameter("@Name",sysRoleInfo.Name),
            new SqlParameter("@DBName",sysRoleInfo.DBName),
            new SqlParameter("@Description",string.IsNullOrEmpty(sysRoleInfo.Description)?"":sysRoleInfo.Description),
            new SqlParameter("@RoleType",sysRoleInfo.RoleType),
            new SqlParameter("@Code",sysRoleInfo.Code),
            new SqlParameter("@Status",sysRoleInfo.Status),
            new SqlParameter("@CreateTime",sysRoleInfo.CreateTime),
            new SqlParameter("@CreatePerson",sysRoleInfo.CreatePerson)
            };

            //执行命令返回结果
            try
            {
                cmd.StoredUpdate("UP_SysRoleInfo_Insert", sqlparams);
                num = 1;
            }
            catch (Exception ex)
            {
                Logger.LogError("UP_Sys_SysRoleInfo_Insert", "UP_Sys_SysRoleInfo_Insert", 0, 1, ex, "", "");
            }
            return num;
        }

        /// <summary>
        /// 更新SysRoleInfo表记录
        /// </summary>
        /// <param name="SysRoleInfo">SysRoleInfo实体对象</param>
        public static int Update(SysRoleInfo sysRoleInfo)
        {
            int num = -1;

            //创建cmd对象
            HIDB.dbo cmd = HIDB.common.make();

            //添加输入输出参数
            IDataParameter[] sqlparams = {
            new SqlParameter("@Id",sysRoleInfo.Id),
            new SqlParameter("@Name",sysRoleInfo.Name),
            new SqlParameter("@Description",sysRoleInfo.Description),
            new SqlParameter("@RoleType",sysRoleInfo.RoleType),
            new SqlParameter("@Code",sysRoleInfo.Code),
            new SqlParameter("@Status",sysRoleInfo.Status),
            new SqlParameter("@UpdateTime",sysRoleInfo.UpdateTime),
            new SqlParameter("@UpdatePerson",sysRoleInfo.UpdatePerson)
            };

            //执行命令返回结果
            try
            {
                cmd.StoredUpdate("UP_SysRoleInfo_Update", sqlparams);
                num = 1;
            }
            catch (Exception ex)
            {
                Logger.LogError("UP_Sys_SysRoleInfo_Insert", "UP_Sys_SysRoleInfo_Insert", 0, 1, ex, "", "");
            }

            return num;
        }

        /// <summary>
        /// 根据Id字段删除SysRoleInfo表信息
        /// </summary>
        /// <param name="id">Id</param>
        public static int Delete(string id)
        {
            int num = -1;

            //创建Database对象          
            HIDB.dbo cmd = HIDB.common.make();

            //添加输入输出参数
            IDataParameter[] sqlparams = {
            new SqlParameter("@Id",id),            
            };

            //执行命令返回结果
            try
            {
                cmd.StoredUpdate("UP_Sys_RoleInfo_Insert", sqlparams);
                num = 1;
            }
            catch (Exception ex)
            {
                Logger.LogError("UP_Sys_RoleInfo_Insert", "UP_Sys_RoleInfo_Insert", 0, 1, ex, "", "");
            }
            return num;
        }
         
        /// <summary>
        /// 根据实体获取SysRoleInfo实体List对象
        /// </summary>
        /// <param name="id">Id</param>
        /// <returns>SysRoleInfo实体对象</returns>
        public static IList<SysRoleInfo> GetList(IDataParameter[] par)
        {
            IList<SysRoleInfo> list = new List<SysRoleInfo>();

            //创建DbCommand对象
            HIDB.dbo cmd = HIDB.common.make();

            //执行命令返回结果
            try
            {
                DataTable dt = cmd.StoredDataTable("[dbo].[UP_SysRoleInfo_GetList]", par);
                list = Common.DBConvert.DataTableToList<SysRoleInfo>(dt);
            }
            catch (Exception ex)
            {
                Logger.LogError("UP_Sys_SysRoleInfo_Select", "UP_Sys_SysRoleInfo_Select", 0, 1, ex, "", "");
            }
            if (list != null)
            {
                return list;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 根据实体获取SysRoleInfo实体List对象
        /// </summary>
        /// <param name="par"> </param>
        /// <returns>SysRoleInfo实体对象</returns>
        public static int GetListCount(IDataParameter[] par)
        {
            HIDB.dbo cmd = HIDB.common.make();

            //执行命令返回结果
            try
            {
                DataTable dt = cmd.StoredDataTable("[dbo].[UP_SysRoleInfo_GetCount]", par);
                if (dt != null && dt.Rows.Count > 0)
                {
                    return Int32.Parse(dt.Rows[0]["Count"].ToString());
                }
                else
                    return 0;
            }
            catch (Exception ex)
            {
                Logger.LogError("UP_Sys_SysRoleInfo_Select", "UP_Sys_SysRoleInfo_Select", 0, 1, ex, "", "");
                return 0;
            }
        }

        /// <summary>
        /// 生成SysRoleInfo实体对象
        /// </summary>
        private static List<SysRoleInfo> CreateSysRoleInfo(DataTable dt)
        {
            var list = new List<SysRoleInfo>();
            for (int j = 0; j < dt.Rows.Count; j++)
            {
                var mySysRoleInfo = new SysRoleInfo
                {
                    Id = DBConvert.GetString(dt.Rows[j], "Id"),
                    Name = DBConvert.GetString(dt.Rows[j], "Name"),
                    Description = DBConvert.GetString(dt.Rows[j], "Description"),
                    RoleType = DBConvert.GetInt32(dt.Rows[j], "RoleType"),
                    Code = DBConvert.GetAnsiString(dt.Rows[j], "Code"),
                    Status = DBConvert.GetAnsiString(dt.Rows[j], "Status"),
                    CreateTime = DBConvert.GetDateTime(dt.Rows[j], "CreateTime"),
                    CreatePerson = DBConvert.GetString(dt.Rows[j], "CreatePerson"),
                    UpdateTime = DBConvert.GetDateTime(dt.Rows[j], "UpdateTime"),
                    UpdatePerson = DBConvert.GetString(dt.Rows[j], "UpdatePerson"),
                    DeleteUser = DBConvert.GetAnsiString(dt.Rows[j], "DeleteUser"),
                    DeleteTime = DBConvert.GetDateTime(dt.Rows[j], "DeleteTime"),
                    IsDelete = DBConvert.GetInt32(dt.Rows[j], "IsDelete")
                };
                list.Add(mySysRoleInfo);
            }
            return list;
        }

        public static int InsertCompetence(IDataParameter[] paras)
        {
            int num = -1;

            //创建cmd对象
            HIDB.dbo cmd = HIDB.common.make();

            //执行命令返回结果
            try
            {
                cmd.StoredUpdate("UP_RoleCompetence_Insert", paras);
                num = 1;
            }
            catch (Exception ex)
            {
                Logger.LogError("UP_Sys_SysRoleInfo_Insert", "UP_Sys_SysRoleInfo_Insert", 0, 1, ex, "", "");
            }
            return num;
        }

        public static int DeleteCompetence(IDataParameter[] paras1)
        {
            int num = -1;

            //创建cmd对象
            HIDB.dbo cmd = HIDB.common.make();

            //执行命令返回结果
            try
            {
                cmd.StoredUpdate("[dbo].[UP_RoleCompetence_Delete]", paras1);
                num = 1;
            }
            catch (Exception ex)
            {
                Logger.LogError("UP_Sys_SysRoleInfo_Insert", "UP_Sys_SysRoleInfo_Insert", 0, 1, ex, "", "");
            }
            return num;
        }

        public static int InsertTarge(IDataParameter[] paras)
        {
            int num = -1;

            //创建cmd对象
            HIDB.dbo cmd = HIDB.common.make();

            //执行命令返回结果
            try
            {
                cmd.StoredUpdate("UP_RoleTarge_Insert", paras);
                num = 1;
            }
            catch (Exception ex)
            {
                Logger.LogError("UP_RoleTarge_Insert", "UP_RoleTarge_Insert", 0, 1, ex, "", "");
            }
            return num;
        }

        public static int InsertUser(IDataParameter[] paras)
        {
            int num = -1;

            //创建cmd对象
            HIDB.dbo cmd = HIDB.common.make();

            //执行命令返回结果
            try
            {
                cmd.StoredUpdate("UP_RoleUser_Insert", paras);
                num = 1;
            }
            catch (Exception ex)
            {
                Logger.LogError("UP_RoleUser_Insert", "UP_RoleUser_Insert", 0, 1, ex, "", "");
            }
            return num;
        }

        public static int DeleteTarge(IDataParameter[] paras)
        {
            int num = -1;

            //创建cmd对象
            HIDB.dbo cmd = HIDB.common.make();

            //执行命令返回结果
            try
            {
                cmd.StoredUpdate("UP_RoleTarge_Delete", paras);
                num = 1;
            }
            catch (Exception ex)
            {
                Logger.LogError("UP_RoleTarge_Delete", "UP_RoleTarge_Delete", 0, 1, ex, "", "");
            }
            return num;
        }

        public static int DeleteUser(IDataParameter[] paras1)
        {
            int num = -1;

            //创建cmd对象
            HIDB.dbo cmd = HIDB.common.make();

            //执行命令返回结果
            try
            {
                cmd.StoredUpdate("dbo.[UP_RoleUser_Delete_ByRoleID]", paras1);
                num = 1;
            }
            catch (Exception ex)
            {
                Logger.LogError("UP_Sys_SysRoleInfo_Insert", "UP_Sys_SysRoleInfo_Insert", 0, 1, ex, "", "");
            }
            return num;
        }

        public static DataTable SelectTarge(IDataParameter[] paras)
        {
            DataTable dt = new DataTable();
            //创建cmd对象
            HIDB.dbo cmd = HIDB.common.make();

            //执行命令返回结果
            try
            {
                dt = cmd.StoredDataTable("[dbo].[UP_RoleTarge_Select]", paras);
            }
            catch (Exception ex)
            {
                Logger.LogError("UP_RoleTarge_Select", "UP_RoleTarge_Select", 0, 1, ex, "", "");
            }
            return dt;
        }

        public static DataTable SelectUser(IDataParameter[] paras1)
        {
            DataTable dt = new DataTable();
            //创建cmd对象
            HIDB.dbo cmd = HIDB.common.make();

            //执行命令返回结果
            try
            {
                dt = cmd.StoredDataTable("[dbo].[UP_RoleUser_Select]", paras1);
            }
            catch (Exception ex)
            {
                Logger.LogError("UP_RoleUser_Select", "UP_RoleUser_Select", 0, 1, ex, "", "");
            }
            return dt;
        }

        public static DataTable SelectCompetence(IDataParameter[] paras1)
        {

            DataTable dt = new DataTable();
            //创建cmd对象
            HIDB.dbo cmd = HIDB.common.make();

            //执行命令返回结果
            try
            {
                dt = cmd.StoredDataTable("[dbo].[UP_RoleCompetence_Select]", paras1);
            }
            catch (Exception ex)
            {
                Logger.LogError("UP_RoleTarge_Select", "UP_RoleTarge_Select", 0, 1, ex, "", "");
            }
            return dt;
        }

        public static DataTable GetRoleTypeByUserName(SqlParameter[] paramsdb)
        {
            DataTable dt = new DataTable();
            //创建cmd对象
            HIDB.dbo cmd = HIDB.common.make();

            //执行命令返回结果
            try
            {
                dt = cmd.StoredDataTable("[dbo].[UP_getRoleTypeByUserName]", paramsdb);
            }
            catch (Exception ex)
            {
                Logger.LogError("UP_getRoleTypeByUserName", "UP_getRoleTypeByUserName", 0, 1, ex, "", "");
            }
            return dt;
        }

        public static int DeleteRow(SqlParameter[] par)
        {
            int num = -1;

            //创建cmd对象
            HIDB.dbo cmd = HIDB.common.make();

            //执行命令返回结果
            try
            {
                cmd.StoredUpdate("[UP_SysRoleInfo_Delete]", par);
                num = 1;
            }
            catch (Exception ex)
            {
                Logger.LogError("UP_Sys_SysRoleInfo_Insert", "UP_Sys_SysRoleInfo_Insert", 0, 1, ex, "", "");
            }
            return num;
        }

        public static int GetRoleInfoByCode(SqlParameter[] par)
        {
            DataTable dt = new DataTable();
            //创建cmd对象
            HIDB.dbo cmd = HIDB.common.make();

            //执行命令返回结果
            try
            {
                dt = cmd.StoredDataTable("[dbo].[UP_SysRoleInfo_Select_ByCode]", par);
            }
            catch (Exception ex)
            {
                Logger.LogError("UP_getRoleTypeByUserName", "UP_getRoleTypeByUserName", 0, 1, ex, "", "");
            }
            return dt.Rows.Count;
        }
    }
}